#include <iostream>
#include "krpc/udp.h"
#include "krpc/tcp.h"
#include "krpc/localstream.h"
#include "krpc/localdgram.h"
#include "krpc/subcribe.h"

struct hehe
{
    int a;
    int b;
    MSGPACK_DEFINE(a,b);

	void print(std::string s1, std::string s2, int i)
	{
		std::cout << s1 << s2 << i << std::endl;
	}

	void print3(int v, std::string s1, std::string s2)
	{
		std::cout << "v = " << v << " " << s1 << s2 << std::endl;
	}

	static void pr(std::string s1, std::string s2)
	{
		std::cout << s1 << s2 << std::endl;
	}
};

void print(struct hehe hi)
{
	std::cout << "a: " << hi.a << ", b: " << hi.b << std::endl;
}

int main(int argc, char const *argv[])
{
	//KRPC::UDP com("127.0.0.1", 9000);
	//KRPC::TCP com("127.0.0.1", 9001);
	//KRPC::LOCALDGRAM com("unix");
	KRPC::LOCALSTREAM com("unix");
	KRPC::MultiSubcribe ms(com, 3000);
	//以lambda函数作为回调处理
    ms.subcribe("sub", [](std::string str, int i){
		std::cout << "str: " << str << ", i: " << i << std::endl;
	});

	struct hehe hi;
	//以全局函数作为回调处理
    ms.subcribe("hehe", print);
	//以类普通成员函数作为回调处理
	ms.subcribe("hello", &hehe::print, &hi);
	
	//以类普通成员函数转换为std::function作为回调处理
	//std::function<void(std::string, std::string)> f = std::bind(&hehe::print3, &hi, 360, std::placeholders::_1, std::placeholders::_2);
	//ms.subcribe("hello", f);
	
	//以类静态成员函数作为函数处理
	//ms.subcribe("hello", &hehe::pr);

	ms.run();
	return 0;
}
